/*
 * @day07ription: 
 * @Author: 于子续
 * @Date: 2024-09-03 15:54:17
 * @LastEditors: 于子续
 * @LastEditTime: 2024-09-03 15:55:56
 */
package day07;

public class Test7_PrimeNumber {
    public static void main(String[] args) {
        int count = 0; // 用于计数找到的素数个数
        System.out.println("101到200之间的素数有：");

        for (int number = 101; number <= 200; number++) {
            if (isPrime(number)) {
                System.out.print(number + " ");
                count++;
            }
        }

        System.out.println("\n总共有 " + count + " 个素数。");
    }

    // 方法：检查一个数是否为素数
    public static boolean isPrime(int num) {
        if (num <= 1) {
            return false;
        }

        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                return false;
            }
        }

        return true;
    }
}
